package cn.mulanbay.api.system.factory;

import cn.mulanbay.api.system.bean.RemoteOperationLog;
import cn.mulanbay.api.system.bean.RemoteSystemLog;
import cn.mulanbay.api.system.service.RemoteLogService;
import cn.mulanbay.common.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * 日志服务降级处理
 *
 * @author fenghong
 */
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);

    @Override
    public RemoteLogService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable);
        return new RemoteLogService() {

            @Override
            public R<Long> addSystemLog(RemoteSystemLog log) {
                return R.fail("增加系统日志失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> addOperationLog(RemoteOperationLog log) {
                return R.fail("增加操针日志失败:" + throwable.getMessage());
            }

        };
    }
}
